package org.jin.samples.test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.jin.samples.dao.IManageStudentDao;
import org.jin.samples.dao.impl.ManageStudentDao;
import org.jin.samples.model.ExamTest;
import org.jin.samples.model.ExamUser;
import org.jin.samples.model.vo.ExamTestVO;
import org.jin.samples.model.vo.ExamUserVO;
import org.jin.samples.service.IManageStudentService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"file:WebContent/WEB-INF/viewspace-servlet.xml"})
public class ManageStudent {

	@Autowired
	private IManageStudentService manageStudentService;
		   
	@Autowired
	private IManageStudentDao manageStudentDao;
	
	
	@Test
	public void test() {
			ExamUserVO e = new ExamUserVO();
			e.setUserId("123");
			e.setAddress("东莞");
			e.setUserName("小小");
			//e.setBirthday(birthday);
			e.setEmail("22323@qq.com");
			e.setGender(1);
			e.setTel("12131314");
			//e.setUserId(userId);
		manageStudentService.create(e);
		System.out.println("添加成功");
		
		}
	
	@Test
	public void test1() {
			//ExamUserVO e = new ExamUserVO();
			ExamUser e = new ExamUser();
			e.setUserId("125");
			e.setAddress("东莞");
			e.setUserName("小小");
			//e.setBirthday("2017-05-24");
			e.setEmail("22323@qq.com");
			e.setGender(1);
			e.setTel("12131314");
			e.setLastLockTime(new Date());
			e.setLoginFailCount(1);
			e.setPassword("123");
			//e.setUserId(userId);
			manageStudentDao.add(e);
		System.out.println("添加成功");
		}
	
	@Test
	public void test3() {
			//ExamUserVO e = new ExamUserVO();
		ExamUserVO e = new ExamUserVO();
		e.setUserId("133124");
		e.setAddress("东莞");
		e.setUserName("冰冰");
		//e.setBirthday(birthday);
		e.setEmail("520@qq.com");
		e.setGender(0);
		e.setTel("12131314");
		e.setBirthday("2017-05-24");
			//e.setUserId(userId);
		manageStudentService.Updata(e);
		System.out.println("修改成功");
		}
	
	
	@Test
	public void test4(){
		ExamUser e = new ExamUser();
		e.setUserId("133124");
//		e.setAddress("东莞1");
//		e.setUserName("晓丽1");
//		//e.setBirthday(birthday);
//		e.setEmail("520@qq.com");
//		e.setGender(0);
//		e.setTel("12131314");
//		e.setBirthday("2017-05-24");
		ExamUser e1 = manageStudentDao.get(e.getUserId());
		if(e1 != null){
			e1.setUserName("我只是变了个名字");
			manageStudentDao.saveOrUpdate(e1);
		}
		System.out.println("成功");
	}
	
	@Test
	public void test5(){
		manageStudentService.delete("125");
		System.out.println("成功...");
	}
	
	@Test
	public void test6(){
		List<ExamUser> entities = new ArrayList<ExamUser>();
		ExamUser e = new ExamUser();
		e.setUserId("135");
		e.setAddress("东莞");
		e.setUserName("冰冰3");
		e.setBirthday("2017-05-24");
		e.setEmail("520@qq.com");
		e.setGender(0);
		e.setTel("12131314");
		e.setPassword("123");
		e.setLoginFailCount(0);
		e.setLastLockTime(new Date());
		
		ExamUser e1 = new ExamUser();
		e.setUserId("136");
		e.setAddress("东莞");
		e.setUserName("冰冰4");
		e.setBirthday("2017-05-24");
		e.setEmail("521@qq.com");
		e.setGender(0);
		e.setTel("12131314");
		e.setPassword("123");
		e.setLoginFailCount(0);
		e.setLastLockTime(new Date());
		entities.add(e);
		manageStudentDao.save(entities);
		System.out.println("成功...");
	}
	
	@Test
	public void updata(){
	
		ExamUserVO vo = manageStudentService.findByIdUser("1");
		System.out.println(vo.getLoginFailCount());
		
		vo.setLoginFailCount(vo.getLoginFailCount() +1);
		manageStudentService.UpdataBy(vo);
	}
	
	@Test
	public void test7(){
		ExamUserVO vo = manageStudentService.findByIdUser("1");
		//System.out.println(vo.getExamRole());
	}
	
	@Test
	public void test8(){
		try {
			ExamUser e= manageStudentDao.getUserById("134");
			System.out.println(e.getUserName());
			System.out.println(e.getExamRole());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	
	
}
	
